Repository navigation
Conversation
joewallwork
left a comment
There was a problem hiding this comment.
Thanks for this @wsmoses, it will be a very useful addition.
I have a few comments on Fortran style and formatting. Is there a reason you converted the tests to use double precision rather than real?
Also, I gather these are just examples rather than tests? Just because there doesn't seem to be any value checking for what's printed out.
| flang_filename = f"FlangEnzyme-{version}.so" | ||
| flang_url = f"https://github.com/EnzymeAD/Enzyme/releases/download/nightly/{flang_filename}" | ||
| flang_tmp = Path("/tmp") / flang_filename | ||
| flang_dest = Path(f"/opt/compiler-explorer/{branch}") / flang_filename | ||
| lld_dest = Path(f"/opt/compiler-explorer/{branch}") / f"LLDEnzyme-{version}.so" | ||
|
|
||
| print(f"Downloading {flang_url} to {flang_tmp}") | ||
| try: | ||
| urllib.request.urlretrieve(flang_url, flang_tmp) | ||
| print(f"Moving {flang_tmp} to {flang_dest}") | ||
| shutil.move(str(flang_tmp), str(flang_dest)) | ||
| except Exception as e: | ||
| print(f"FlangEnzyme download unavailable ({e}); falling back to LLDEnzyme-{version}.so") | ||
| if lld_dest.exists(): | ||
| shutil.copy2(str(lld_dest), str(flang_dest)) |
There was a problem hiding this comment.
So the additional code here is to facilitate falling back on LLDEnzyme. Is this just a temporary workaround until EnzymeAD/Enzyme#3551 is merged or do you intend to keep it around?
There was a problem hiding this comment.
Yes — that was only a temporary bootstrap until EnzymeAD/Enzyme#3551 lands. Removed the fallback in 3a3587c so FlangEnzyme-{version}.so and FlangEnzyme-{version}.cfg use the standard nightly download loop directly (we should just merge EnzymeAD/Enzyme#3551 first).
There was a problem hiding this comment.
Are we happy to duplicate this and enzyme_function_hooks.f90 or would it be reasonable to download these two files directly from Enzyme? I imagine that there will be more changes to these files to come and copying them here would mean having to remember to change them here, too.
There was a problem hiding this comment.
Good call — removed both duplicated .f90 files in 3a3587c. install_clang.sh now fetches enzyme_function_hooks.f90 and enzyme.f90 directly from EnzymeAD/Enzyme (main) at Docker build time, and at runtime update-versions.py + entrypoint.sh re-sync and recompile them from /app/Enzyme/enzyme/Fortran/ whenever Enzyme updates.
There was a problem hiding this comment.
It is nowadays considered bad practice to have procedures that don't belong to a module or program. Please could you either put the functions in a module that gets used in the program, or put them following a contains statement in the program?
There was a problem hiding this comment.
Moved square and dsquare into module square_mod (used in program main) in 3a3587c.
| integer :: i | ||
| do i = 1, 4 | ||
| x = dble(i) | ||
| write(*, '(a,f3.1,a,f4.1,a,f3.1,a,f4.1)') & |
There was a problem hiding this comment.
| write(*, '(a,f3.1,a,f4.1,a,f3.1,a,f4.1)') & | |
| write(*, '(2(a,f3.1,a,f4.1))') & |
| ! Reverse-mode gradient of a vector dot product using activity descriptors. | ||
| subroutine vec_dot(n, a, b, res) | ||
| implicit none | ||
| integer, intent(in) :: n | ||
| double precision, dimension(n), intent(in) :: a, b | ||
| double precision, intent(out) :: res | ||
| integer :: i | ||
|
|
||
| res = 0.0d0 | ||
| do i = 1, n | ||
| res = res + a(i) * b(i) | ||
| end do | ||
| end subroutine vec_dot |
There was a problem hiding this comment.
As above - put the subroutine in a module or the program.
There was a problem hiding this comment.
Moved vec_dot under contains in program main in 3a3587c.
|
|
||
| write(*, '(a,f6.1)') 'dot(a, b) =', res | ||
| do i = 1, n | ||
| write(*, '(a,i1,a,f5.1,a,i1,a,f5.1)') & |
There was a problem hiding this comment.
| write(*, '(a,i1,a,f5.1,a,i1,a,f5.1)') & | |
| write(*, '(2(a,i1,a,f5.1))') & |
| ! Forward-mode directional derivative using enzyme_fwddiff. | ||
| subroutine l2_norm_sq(n, x, y) | ||
| implicit none | ||
| integer, intent(in) :: n | ||
| double precision, dimension(n), intent(in) :: x | ||
| double precision, intent(out) :: y | ||
| integer :: i | ||
|
|
||
| y = 0.0d0 | ||
| do i = 1, n | ||
| y = y + x(i) * x(i) | ||
| end do | ||
| end subroutine l2_norm_sq |
There was a problem hiding this comment.
Moved l2_norm_sq under contains in program main in 3a3587c.
|
Thanks for the review @joewallwork! Addressed all comments in 3a3587c:
|
joewallwork
left a comment
There was a problem hiding this comment.
Thanks @wsmoses, this looks good now!
Summary
fortraninrestrictToLanguages(frontend/files/etc/config/compiler-explorer.enzyme.properties).template_files/etc/config/fortran.enzyme.properties.j2configuringflang20-enzyme-mainandflang21-enzyme-main(defaultCompiler=flang21-enzyme-main,compilerType=flang, Intel/AT&T asm, LLVM IR view, execution,--config=FlangEnzyme-<ver>.cfgfor regular and-fltobuilds,-Xflang -loadfor-mllvm -enzyme-*options, andbinaryHideFuncRefor staticlibFortranRuntime.a/libFortranDecimal.asymbols)..modPrecompilation:flang-${v}for LLVM >= 20 infrontend/install_clang.sh, fetchenzyme_function_hooks.f90andenzyme.f90directly fromEnzymeAD/Enzyme, and precompile.modfiles per Flang version soiso_c_binding.modchecksums match.frontend/entrypoint.shto recompile/opt/compiler-explorer/main/fortran/*.f90(synced fromEnzyme/mainbybuilder) with each installed/usr/bin/flang-${v}on startup, and sync/app/compiler-explorer/etc/config/*.enzyme.propertiesinto/app/etc/config/when present so live commit hashes display instead of<unknown>.scripts/update-versions.pyto downloadLLDEnzyme-{version}.so,FlangEnzyme-{version}.so, andFlangEnzyme-{version}.cfg(published by Build and publish FlangEnzyme in nightly C/C++ CI Enzyme#3551), copyEnzyme/enzyme/Fortran/*.f90into/opt/compiler-explorer/main/fortran/, and renderfortran.enzyme.properties.default.f90,dot_product.f90,forward_mode.f90,custom_derivative.f90, andfunction_like.f90underfrontend/files/examples/fortran/.Verification
flang-20andflang-21(assembly, LLVM IR, binary disassembly, and program execution) via a live local Compiler Explorer server (--env enzyme).